<?php
/**
 * This file is part of EasySwoole.
 *
 * @link https://www.easyswoole.com
 * @document https://www.easyswoole.com
 * @contact https://www.easyswoole.com/Preface/contact.html
 * @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
 */

namespace App\Event;

use EasySwoole\Component\Container;
use EasySwoole\Component\Singleton;

class Event extends Container{

    use Singleton;

    const EVENT_DEMO = 'eventDemo';
    const EVENT_AFTER_ORDER_SUBMITTED = 'eventAfterOrderSubmit';
    const EVENT_COUNT_USER = 'eventCountUser';
    const EVENT_COUNT_ORDER_TASK = 'eventCountOrderTask';
    const EVENT_ORDER_AUTO_SETTLE = 'eventOrderAutoSettle';
    public function set($key, $item){
        if(is_callable($item)){
            return parent::set($key, $item);
        }else{
            return false;
        }
    }

    /**
     * @param $event
     * @param ...$args
     * @return false|mixed|null
     * @tag <code>Markup<</code>
     */
    public function hook($event, ...$args){
        $call = $this->get($event);
        if(is_callable($call)){
            return call_user_func($call, ...$args);
        }else{
            return null;
        }
    }
}
